home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
129_01
/
210modem.c
< prev
next >
Wrap
Text File
|
1985-03-09
|
25KB
|
819 lines
/************************************************************************/
/* modem.c */
/* */
/* modem code for Citadel bulletin board system */
/* NB: this code is rather machine-dependent: it will typically */
/* need some twiddling for each new installation. */
/* 82Nov05 CrT */
/************************************************************************/
/************************************************************************/
/* history */
/* */
/* 85Jan12 HAW SECONDSFACTOR == secondsfactor now, for portability. */
/* 84Dec28 HAW Ensure execution of HANGUP when carrier is lost. */
/* 84Dec16 JLS&HAW Start installation of new WC protocol downloader. */
/* 84Aug22 HAW Compilation directive for 8085 chips inserted. */
/* 84Jul08 JLS & HAW ReadFile() fixed for the 255 rollover. */
/* 84Jul03 JLS & HAW All references to putCh changed to putChar. */
/* 84Jun23 HAW & JLS Local unused variables zapped. */
/* 84Mar07 HAW Upgrade to BDS 1.50a begun. */
/* 83Mar01 CrT FastIn() ignores LFs etc -- CRLF folks won't be trapped.*/
/* 83Feb25 CrT Possible fix for backspace-in-message-entry problem. */
/* 83Feb18 CrT fastIn() upload mode cutting in on people. Fixed. */
/* 82Dec16 dvm modemInit revised for FDC-1, with kludge for use with */
/* Big Board development system */
/* 82Dec06 CrT 2.00 release. */
/* 82Nov15 CrT readfile() & sendfile() borrowed from TelEdit.c */
/* 82Nov05 CrT Individual history file established */
/************************************************************************/
#include <210ctdl.h>
/************************************************************************/
/* Contents */
/* */
/* BBSCharReady() returns true if user input is ready */
/* doWC() startup routine for the WC downloader. */
/* # fastIn() kludge code compiling other stuff inline*/
/* getCh() bottom-level console-input filter */
/* # getMod() bottom-level modem-input filter */
/* iChar() top-level user-input function */
/* interact() chat mode */
/* interpret() interprets a configuration routine */
/* KBReady() returns TRUE if a console char is ready */
/* mOReady() returns true if modem can accept a char */
/* modIn() returns a user char */
/* modemInit() top-level initialize-all-modem-stuff */
/* oChar() top-level user-output function */
/* # outMod() bottom-level modem output */
/* pause() pauses for N/100 seconds */
/* # putChar() */
/* readFile() accept a file using WC protocol */
/* receive() read modem char or time out */
/* ringSysop() signal chat-mode request */
/* sendWCChar() Helps chuck output via WC protocol. */
/* */
/* # == routines you should certainly check when porting system */
/************************************************************************/
/************************************************************************/
/* The principal dependencies: */
/* */
/* iChar modIn outMod */
/* modIn getMod getCh mIReady kBReady outMod carrDetect */
/* getMod */
/* getCh */
/* mIReady */
/* kBReady */
/* carrDetect */
/* */
/* oChar outMod */
/* outMod mOReady */
/************************************************************************/
/************************************************************************/
/* BBSCharReady() returns TRUE if char is available from user */
/* NB: user may be on modem, or may be sysop in CONSOLE mode */
/************************************************************************/
char BBSCharReady()
{
char KBReady();
return ((haveCarrier && interpret(pMIReady))
|| (whichIO==CONSOLE && KBReady() )
);
}
/************************************************************************/
/* doWC() is the initialization routine for WC downloading. If */
/* called with mode == STARTUP, it sets up globals and gets ready */
/* for the initial NAK. If mode == anything else, then it cleans */
/* up after the downloader. */
/************************************************************************/
doWC(mode)
char mode; /* See above */
{
int i, m;
if (mode == STARTUP) { /* Setup globals for the coming fun. */
WCError = FALSE;
WCSecNum = 1;
i = 0;
WCChar = 0;
while (1) { /* Get that darn initial NAK */
m = receive(MINUTE);
if (m == CAN || m == ERROR) /* Didn't get initial */
return FALSE; /* NAK, so time out .. */
if (m == NAK) /* There it is! */
return TRUE;
if (++i == ERRORMAX) /* 10 chars, no NAKs? */
return FALSE; /* Then ferget it. */
}
}
else { /* Cleanup after downloader */
if (WCError) return;
for (; WCChar != 0 && sendWCChar(' ');)
; /* Do final sector */
if (WCError) return;
for (i = 0; i < ERRORMAX; i++) {
outMod(EOT);
if (receive(MINUTE) == ACK || !haveCarrier) break;
}
}
}
/************************************************************************/
/* fastIn() is a special kludge to read in text from the modem */
/* as quickly as possible, to allow message upload without */
/* handshaking. Hence we hand-compile some other routines inline */
/* Called only from getText(), when whichIO==MODEM. */
/* Externals: see below */
/* */
/* This code is probably overkill for 300 baud, but it may handle */
/* 1200 baud as well. */
/* */
/* code being speed-optimized would normally be: */
/* */
/* while ( */
/* !( (c=iChar()) == NEWLINE && buf[i-1] == NEWLINE ) */
/* && i < lim */
/* && (haveCarrier || whichIO == CONSOLE) */
/* ) { */
/* if (c != BACKSPACE) buf[i++] = c; */
/* else { */
/* / handle deletes: / */
/* oChar(' '); */
/* oChar(BACKSPACE); */
/* if (i>0 && buf[i-1] != NEWLINE) i--; */
/* else oChar(BELL); */
/* } */
/* } */
/************************************************************************/
#define cursor fpc1 /* external char * */
#define BUFEND fpc2 /* external char * */
#define tryCount fi1 /* external int */
#define isFast fi2 /* external int */
#define ch fc1 /* external char */
#define lastWasNL fc2 /* external char */
#define slow fc3 /* external char */
fastIn(continuing)
char continuing; /* TRUE if we are continuing a message */
{
char cache, notFinished;
int tryStart, shortTime;
isFast = 0;
tryStart = 500*megaHz;
shortTime = 480*megaHz;
cursor = &msgBuf.mbtext[0 ];
BUFEND = &msgBuf.mbtext[MAXTEXT-1];
if (continuing) while (*cursor) ++cursor; /* find where we were */
notFinished = TRUE;
lastWasNL = FALSE;
/* put newline at start of buffer to simplify BACKSPACE check: */
cache = msgBuf.mbtext[-1];
msgBuf.mbtext[-1] = NEWLINE;
while (notFinished && cursor < BUFEND) {
tryCount = tryStart; /* try to be waiting for each char */
while (--tryCount && !interpret(pMIReady));
if (tryCount>shortTime) isFast++;
else isFast--;
if (!tryCount) {
/* no modem char -- take break to check other stuff */
if (KBReady()) {
if (getCh() == SPECIAL) {
mPrintf("\n system is now in CONSOLE mode.\n ");
whichIO = CONSOLE;
notFinished = FALSE;
setUp(FALSE);
}
}
if (!interpret(pCarrDetect)) {
modIn(); /* let modIn() announce it etc */
notFinished = FALSE;
}
} else {
/* time to read modem char: */
switch (ch = filter[ inp(mData) & 0x7F ]) {
case NEWLINE:
if (lastWasNL) {
notFinished = FALSE;
} else {
lastWasNL = TRUE;
*cursor++ = ch;
if (isFast>0 || !termLF) ch = '\r';
else {
oChar('\r');
while (!interpret(pMOReady)); /* for outp() */
}
}
isFast = 0; /* figure speed of each line independently */
break;
case BACKSPACE:
/* people don't upload backspaces --